home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-4.0 / bfd / doc / bfd.info-2 < prev    next >
Encoding:
Text File  |  1991-09-29  |  39.5 KB  |  1,205 lines

  1. Info file bfd.info, produced by Makeinfo, -*- Text -*- from input
  2. file bfd.texinfo.
  3.  
  4.    This file documents the BFD library.
  5.  
  6.    Copyright (C) 1991 Free Software Foundation, Inc.
  7.  
  8.    Permission is granted to make and distribute verbatim copies of
  9. this manual provided the copyright notice and this permission notice
  10. are preserved on all copies.
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, subject to the
  14. terms of the GNU General Public License, which includes the provision
  15. that the entire resulting derived work is distributed under the terms
  16. of a permission notice identical to this one.
  17.  
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21.  
  22.  
  23. 
  24. File: bfd.info,  Node: Relocations,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  25.  
  26. Relocations
  27. ===========
  28.  
  29.    BFD maintains relocations in much the same was as it maintains
  30. symbols; they are left alone until required, then read in en-mass and
  31. traslated into an internal form. There is a common routine
  32. `bfd_perform_relocation' which acts upon the canonical form to to the
  33. actual fixup.
  34.  
  35.    Note that relocations are maintained on a per section basis,
  36. whilst symbols are maintained on a per BFD basis.
  37.  
  38.    All a back end has to do to fit the BFD interface is to create as
  39. many `struct reloc_cache_entry' as there are relocations in a
  40. particuar section, and fill in the right bits:
  41.  
  42. * Menu:
  43.  
  44. * typedef arelent::
  45. * reloc handling functions::
  46.  
  47. `bfd_perform_relocation'
  48. ........................
  49.  
  50.    The relocation routine returns as a status an enumerated type:
  51.  
  52.      typedef enum bfd_reloc_status {
  53.  
  54.    No errors detected
  55.  
  56.        bfd_reloc_ok,
  57.  
  58.    The relocation was performed, but there was an overflow.
  59.  
  60.        bfd_reloc_overflow,
  61.  
  62.    The address to relocate was not within the section supplied
  63.  
  64.        bfd_reloc_outofrange,
  65.  
  66.    Used by special functions
  67.  
  68.        bfd_reloc_continue,
  69.  
  70.    Unused
  71.  
  72.        bfd_reloc_notsupported,
  73.  
  74.    Unsupported relocation size requested.
  75.  
  76.        bfd_reloc_other,
  77.  
  78.    The symbol to relocate against was undefined.
  79.  
  80.        bfd_reloc_undefined,
  81.  
  82.    The relocation was performed, but may not be ok - presently
  83. generated only when linking i960 coff files with i960 b.out symbols.
  84.  
  85.        bfd_reloc_dangerous
  86.         }
  87.       bfd_reloc_status_enum_type;
  88.  
  89.      typedef struct reloc_cache_entry 
  90.      {
  91.  
  92.    A pointer into the canonical table of pointers
  93.  
  94.        struct symbol_cache_entry **sym_ptr_ptr;
  95.  
  96.    offset in section
  97.  
  98.        rawdata_offset address;
  99.  
  100.    addend for relocation value
  101.  
  102.        bfd_vma addend;
  103.  
  104.    if sym is null this is the section
  105.  
  106.        struct sec *section;
  107.  
  108.    Pointer to how to perform the required relocation
  109.  
  110.        CONST struct reloc_howto_struct *howto;
  111.      } arelent;
  112.  
  113. `sym_ptr_ptr'
  114.      The symbol table pointer points to a pointer to the symbol
  115.      ascociated with the relocation request. This would naturaly be
  116.      the pointer into the table returned by the back end's get_symtab
  117.      action. *Note Symbols::. The symbol is referenced through a
  118.      pointer to a pointer so that tools like the linker can fixup all
  119.      the symbols of the same name by modifying only one pointer. The
  120.      relocation routine looks in the symbol and uses the base of the
  121.      section the symbol is attached to and the value of the symbol as
  122.      the initial relocation offset. If the symbol pointer is zero,
  123.      then the section provided is looked up.
  124.  
  125. `address'
  126.      The address field gives the offset in bytes from the base of the
  127.      section data which owns the relocation record to the first byte
  128.      of relocatable information. The actual data relocated will be
  129.      relative to this point - for example, a relocation type which
  130.      modifies the bottom two bytes of a four byte word would not
  131.      touch the first byte pointed to in a big endian world.
  132.  
  133. `addend'
  134.      The addend is a value provided by the back end to be added (!)
  135.      to the relocation offset. It's interpretation is dependent upon
  136.      the howto.  For example, on the 68k the code:
  137.  
  138.                   char foo[];
  139.                   main()
  140.                           {
  141.                           return foo[0x12345678];
  142.                           }
  143.  
  144.      Could be compiled into:
  145.  
  146.                   linkw fp,#-4
  147.                   moveb @#12345678,d0
  148.                   extbl d0
  149.                   unlk fp
  150.                   rts
  151.  
  152.      This could create a reloc pointing to foo, but leave the offset
  153.      in the data (something like)
  154.  
  155.           RELOCATION RECORDS FOR [.text]:
  156.           OFFSET   TYPE      VALUE 
  157.           00000006 32        _foo
  158.           
  159.           00000000 4e56 fffc          ; linkw fp,#-4
  160.           00000004 1039 1234 5678     ; moveb @#12345678,d0
  161.           0000000a 49c0               ; extbl d0
  162.           0000000c 4e5e               ; unlk fp
  163.           0000000e 4e75               ; rts
  164.  
  165.      Using coff and an 88k, some instructions don't have enough space
  166.      in them to represent the full address range, and pointers have
  167.      to be loaded in two parts. So you'd get something like:
  168.  
  169.                   or.u     r13,r0,hi16(_foo+0x12345678)
  170.                   ld.b     r2,r13,lo16(_foo+0x12345678)
  171.                   jmp      r1
  172.  
  173.      This whould create two relocs, both pointing to _foo, and with
  174.      0x12340000 in their addend field. The data would consist of:
  175.  
  176.  
  177.                     RELOCATION RECORDS FOR [.text]:
  178.           OFFSET   TYPE      VALUE 
  179.           00000002 HVRT16    _foo+0x12340000
  180.           00000006 LVRT16    _foo+0x12340000
  181.           
  182.           00000000 5da05678           ; or.u r13,r0,0x5678
  183.           00000004 1c4d5678           ; ld.b r2,r13,0x5678
  184.           00000008 f400c001           ; jmp r1
  185.  
  186.      The relocation routine digs out the value from the data, adds it
  187.      to the addend to get the original offset and then adds the value
  188.      of _foo.  Note that all 32 bits have to be kept around
  189.      somewhere, to cope with carry from bit 15 to bit 16.
  190.  
  191.      On further example is the sparc and the a.out format. The sparc
  192.      has a similar problem to the 88k, in that some instructions
  193.      don't have room for an entire offset, but on the sparc the parts
  194.      are created odd sized lumps. The designers of the a.out format
  195.      chose not to use the data within the section for storing part of
  196.      the offset; all the offset is kept within the reloc. Any thing
  197.      in the data should be ignored.
  198.  
  199.                   save %sp,-112,%sp
  200.                   sethi %hi(_foo+0x12345678),%g2
  201.                   ldsb [%g2+%lo(_foo+0x12345678)],%i0
  202.                   ret
  203.                   restore
  204.  
  205.      Both relocs contains a pointer to foo, and the offsets would
  206.      contain junk.
  207.  
  208.           RELOCATION RECORDS FOR [.text]:
  209.           OFFSET   TYPE      VALUE 
  210.           00000004 HI22      _foo+0x12345678
  211.           00000008 LO10      _foo+0x12345678
  212.           
  213.           00000000 9de3bf90     ; save %sp,-112,%sp
  214.           00000004 05000000     ; sethi %hi(_foo+0),%g2
  215.           00000008 f048a000     ; ldsb [%g2+%lo(_foo+0)],%i0
  216.           0000000c 81c7e008     ; ret
  217.           00000010 81e80000     ; restore
  218.  
  219. `section'
  220.      The section field is only used when the symbol pointer field is
  221.      null.  It supplies the section into which the data should be
  222.      relocated. The field's main use comes from assemblers which do
  223.      most of the symbol fixups themselves; an assembler may take an
  224.      internal reference to a label, but since it knows where the
  225.      label is, it can turn the relocation request from a symbol
  226.      lookup into a section relative relocation - the relocation
  227.      emitted has no symbol, just a section to relocate against.
  228.  
  229.      I'm not sure what it means when both a symbol pointer an a
  230.      section pointer are present. Some formats use this sort of
  231.      mechanism to describe PIC relocations, but BFD can't to that
  232.      sort of thing yet.
  233.  
  234. `howto'
  235.      The howto field can be imagined as a relocation instruction. It
  236.      is a pointer to a struct which contains information on what to
  237.      do with all the other information in the reloc record and data
  238.      section. A back end would normally have a relocation instruction
  239.      set and turn relocations into pointers to the correct structure
  240.      on input - but it would be possible to create each howto field
  241.      on demand.
  242.  
  243. `reloc_howto_type'
  244. ..................
  245.  
  246.    The `reloc_howto_type' is a structure which contains all the
  247. information that BFD needs to know to tie up a back end's data.
  248.  
  249.      typedef CONST struct reloc_howto_struct 
  250.      {
  251.  
  252.    The type field has mainly a documetary use - the back end can to
  253. what it wants with it, though the normally the back end's external
  254. idea of what a reloc number would be would be stored in this field.
  255. For example, the a PC relative word relocation in a coff environment
  256. would have the type 023 - because that's what the outside world calls
  257. a R_PCRWORD reloc.
  258.  
  259.        unsigned int type;
  260.  
  261.    The value the final relocation is shifted right by. This drops
  262. unwanted data from the relocation.
  263.  
  264.        unsigned int rightshift;
  265.  
  266.    The size of the item to be relocated - 0, is one byte, 1 is 2
  267. bytes, 3 is four bytes.
  268.  
  269.        unsigned int size;
  270.  
  271.    Now obsolete
  272.  
  273.        unsigned int bitsize;
  274.  
  275.    Notes that the relocation is relative to the location in the data
  276. section of the addend. The relocation function will subtract from the
  277. relocation value the address of the location being relocated.
  278.  
  279.        boolean pc_relative;
  280.  
  281.    Now obsolete
  282.  
  283.        unsigned int bitpos;
  284.  
  285.    Now obsolete
  286.  
  287.        boolean absolute;
  288.  
  289.    Causes the relocation routine to return an error if overflow is
  290. detected when relocating.
  291.  
  292.        boolean complain_on_overflow;
  293.  
  294.    If this field is non null, then the supplied function is called
  295. rather than the normal function. This allows really strange
  296. relocation methods to be accomodated (eg, i960 callj instructions).
  297.  
  298.        bfd_reloc_status_enum_type (*special_function)();
  299.  
  300.    The textual name of the relocation type.
  301.  
  302.        char *name;
  303.  
  304.    When performing a partial link, some formats must modify the
  305. relocations rather than the data - this flag signals this.
  306.  
  307.        boolean partial_inplace;
  308.  
  309.    The src_mask is used to select what parts of the read in data are
  310. to be used in the relocation sum. Eg, if this was an 8 bit bit of
  311. data which we read and relocated, this would be 0x000000ff. When we
  312. have relocs which have an addend, such as sun4 extended relocs, the
  313. value in the offset part of a relocating field is garbage so we never
  314. use it. In this case the mask would be 0x00000000.
  315.  
  316.        bfd_word src_mask;
  317.  
  318.    The dst_mask is what parts of the instruction are replaced into
  319. the instruction. In most cases src_mask == dst_mask, except in the
  320. above special case, where dst_mask would be 0x000000ff, and src_mask
  321. would be 0x00000000.
  322.  
  323.        bfd_word dst_mask;
  324.  
  325.    When some formats create PC relative instructions, they leave the
  326. value of the pc of the place being relocated in the offset slot of
  327. the instruction, so that a PC relative relocation can be made just by
  328. adding in an ordinary offset (eg sun3 a.out). Some formats leave the
  329. displacement part of an instruction empty (eg m88k bcs), this flag
  330. signals the fact.
  331.  
  332.        boolean pcrel_offset;
  333.      } reloc_howto_type;
  334.  
  335. `HOWTO'
  336. .......
  337.  
  338.    The HOWTO define is horrible and will go away.
  339.  
  340.      #define HOWTO(C, R,S,B, P, BI, ABS, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
  341.        {(unsigned)C,R,S,B, P, BI, ABS,O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
  342.  
  343. `reloc_chain'
  344. .............
  345.  
  346.      typedef unsigned char bfd_byte;
  347.      
  348.      typedef struct relent_chain {
  349.        arelent relent;
  350.        struct   relent_chain *next;
  351.      } arelent_chain;
  352.  
  353.    If an output_bfd is supplied to this function the generated image
  354. will be relocatable, the relocations are copied to the output file
  355. after they have been changed to reflect the new state of the world. 
  356. There are two ways of reflecting the results of partial linkage in an
  357. output file; by modifying the output data in place, and by modifying
  358. the relocation record. Some native formats (eg basic a.out and basic
  359. coff) have no way of specifying an addend in the relocation type, so
  360. the addend has to go in the output data.  This is no big deal since
  361. in these formats the output data slot will always be big enough for
  362. the addend. Complex reloc types with addends were invented to solve
  363. just this problem.
  364.  
  365.      bfd_reloc_status_enum_type bfd_perform_relocation(bfd * abfd,
  366.                              arelent *reloc_entry,
  367.                              PTR data,
  368.                              asection *input_section,
  369.                              bfd *output_bfd);
  370.  
  371.  
  372. 
  373. File: bfd.info,  Node: Core Files,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  374.  
  375. Core files
  376. ==========
  377.  
  378.    Buff output this facinating topic
  379.  
  380. `bfd_core_file_failing_command'
  381. ...............................
  382.  
  383.    Returns a read-only string explaining what program was running
  384. when it failed and produced the core file being read
  385.  
  386.      CONST char * bfd_core_file_failing_command(bfd *);
  387.  
  388. `bfd_core_file_failing_signal'
  389. ..............................
  390.  
  391.    Returns the signal number which caused the core dump which
  392. generated the file the BFD is attached to.
  393.  
  394.      int bfd_core_file_failing_signal(bfd *);
  395.  
  396. `core_file_matches_executable_p'
  397. ................................
  398.  
  399.    Returns `true' if the core file attached to CORE_BFD was generated
  400. by a run of the executable file attached to EXEC_BFD, or else `false'.
  401.  
  402.      boolean core_file_matches_executable_p(bfd *core_bfd, bfd *exec_bfd);
  403.  
  404.  
  405. 
  406. File: bfd.info,  Node: Targets,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  407.  
  408. Targets
  409. =======
  410.  
  411.    Each port of BFD to a different machine requries the creation of a
  412. target back end. All the back end provides to the root part of BFD is
  413. a structure containing pointers to functions which perform certain
  414. low level operations on files. BFD translates the applications's
  415. requests through a pointer into calls to the back end routines.
  416.  
  417.    When a file is opened with `bfd_openr', its format and target are
  418. unknown. BFD uses various mechanisms to determine how to interpret
  419. the file. The operatios performed are:
  420.  
  421.    * First a BFD is created by calling the internal routine
  422.      `new_bfd', then `bfd_find_target' is called with the target
  423.      string supplied to `bfd_openr' and the new BFD pointer.
  424.  
  425.    * If a null target string was provided to `bfd_find_target', it
  426.      looks up the environment variable `GNUTARGET' and uses that as
  427.      the target string.
  428.  
  429.    * If the target string is still NULL, or the target string is
  430.      `default', then the first item in the target vector is used as
  431.      the target type. *Note bfd_target::.
  432.  
  433.    * Otherwise, the elements in the target vector are inspected one
  434.      by one, until a match on target name is found. When found, that
  435.      is used.
  436.  
  437.    * Otherwise the error `invalid_target' is returned to `bfd_openr'.
  438.  
  439.    * `bfd_openr' attempts to open the file using `bfd_open_file', and
  440.      returns the BFD.
  441.  
  442.    Once the BFD has been opened and the target selected, the file
  443. format may be determined. This is done by calling `bfd_check_format'
  444. on the BFD with a suggested format. The routine returns `true' when
  445. the application guesses right.
  446.  
  447. `bfd_target'
  448. ............
  449.  
  450.  
  451. 
  452. File: bfd.info,  Node: bfd_target
  453.  
  454. bfd_target
  455. ----------
  456.  
  457.    This structure contains everything that BFD knows about a target. 
  458. It includes things like its byte order, name, what routines to call
  459. to do various operations, etc.
  460.  
  461.    Every BFD points to a target structure with its "xvec" member.
  462.  
  463.    Shortcut for declaring fields which are prototyped function
  464. pointers, while avoiding anguish on compilers that don't support
  465. protos.
  466.  
  467.      #define SDEF(ret, name, arglist) \
  468.                      PROTO(ret,(*name),arglist)
  469.      #define SDEF_FMT(ret, name, arglist) \
  470.                      PROTO(ret,(*name[bfd_type_end]),arglist)
  471.  
  472.    These macros are used to dispatch to functions through the
  473. bfd_target vector. They are used in a number of macros further down
  474. in `bfd.h', and are also used when calling various routines by hand
  475. inside the BFD implementation.  The "arglist" argument must be
  476. parenthesized; it contains all the arguments to the called function.
  477.  
  478.      #define BFD_SEND(bfd, message, arglist) \
  479.                     ((*((bfd)->xvec->message)) arglist)
  480.  
  481.    For operations which index on the BFD format
  482.  
  483.      #define BFD_SEND_FMT(bfd, message, arglist) \
  484.                  (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
  485.  
  486.    This is the struct which defines the type of BFD this is.  The
  487. "xvec" member of the struct `bfd' itself points here.  Each module
  488. that implements access to a different target under BFD, defines one
  489. of these.
  490.  
  491.    FIXME, these names should be rationalised with the names of the
  492. entry points which call them. Too bad we can't have one macro to
  493. define them both!
  494.  
  495.      typedef struct bfd_target
  496.      {
  497.  
  498.    identifies the kind of target, eg SunOS4, Ultrix, etc
  499.  
  500.        char *name;
  501.  
  502.    The "flavour" of a back end is a general indication about the
  503. contents of a file.
  504.  
  505.        enum target_flavour_enum {
  506.          bfd_target_aout_flavour_enum,
  507.          bfd_target_coff_flavour_enum,
  508.          bfd_target_ieee_flavour_enum,
  509.          bfd_target_oasys_flavour_enum,
  510.          bfd_target_srec_flavour_enum} flavour;
  511.  
  512.    The order of bytes within the data area of a file.
  513.  
  514.        boolean byteorder_big_p;
  515.  
  516.    The order of bytes within the header parts of a file.
  517.  
  518.        boolean header_byteorder_big_p;
  519.  
  520.    This is a mask of all the flags which an executable may have set -
  521. from the set `NO_FLAGS', `HAS_RELOC', ...`D_PAGED'.
  522.  
  523.        flagword object_flags;
  524.  
  525.    This is a mask of all the flags which a section may have set -
  526. from the set `SEC_NO_FLAGS', `SEC_ALLOC', ...`SET_NEVER_LOAD'.
  527.  
  528.        flagword section_flags;
  529.  
  530.    The pad character for filenames within an archive header.
  531.  
  532.        char ar_pad_char;
  533.  
  534.    The maximum number of characters in an archive header.
  535.  
  536.       unsigned short ar_max_namelen;
  537.  
  538.    The minimum alignment restriction for any section.
  539.  
  540.        unsigned int align_power_min;
  541.  
  542.    Entries for byte swapping for data. These are different to the
  543. other entry points, since they don't take BFD as first arg.  Certain
  544. other handlers could do the same.
  545.  
  546.        SDEF (bfd_vma,      bfd_getx64, (bfd_byte *));
  547.        SDEF (void,         bfd_putx64, (bfd_vma, bfd_byte *));
  548.        SDEF (bfd_vma, bfd_getx32, (bfd_byte *));
  549.        SDEF (void,         bfd_putx32, (bfd_vma, bfd_byte *));
  550.        SDEF (bfd_vma, bfd_getx16, (bfd_byte *));
  551.        SDEF (void,         bfd_putx16, (bfd_vma, bfd_byte *));
  552.  
  553.    Byte swapping for the headers
  554.  
  555.        SDEF (bfd_vma,   bfd_h_getx64, (bfd_byte *));
  556.        SDEF (void,          bfd_h_putx64, (bfd_vma, bfd_byte *));
  557.        SDEF (bfd_vma,  bfd_h_getx32, (bfd_byte *));
  558.        SDEF (void,          bfd_h_putx32, (bfd_vma, bfd_byte *));
  559.        SDEF (bfd_vma,  bfd_h_getx16, (bfd_byte *));
  560.        SDEF (void,          bfd_h_putx16, (bfd_vma, bfd_byte *));
  561.  
  562.    Format dependent routines, these turn into vectors of entry points
  563. within the target vector structure; one for each format to check.
  564.  
  565.    Check the format of a file being read.  Return bfd_target * or
  566. zero.
  567.  
  568.        SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *));
  569.  
  570.    Set the format of a file being written.
  571.  
  572.        SDEF_FMT (boolean,            _bfd_set_format, (bfd *));
  573.  
  574.    Write cached information into a file being written, at bfd_close.
  575.  
  576.        SDEF_FMT (boolean,            _bfd_write_contents, (bfd *));
  577.  
  578.    The following functions are defined in `JUMP_TABLE'. The idea is
  579. that the back end writer of `foo' names all the routines
  580. `foo_'ENTRY_POINT, `JUMP_TABLE' will built the entries in this
  581. structure in the right order.
  582.  
  583.    Core file entry points
  584.  
  585.        SDEF (char *, _core_file_failing_command, (bfd *));
  586.        SDEF (int,    _core_file_failing_signal, (bfd *));
  587.        SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *));
  588.  
  589.    Archive entry points
  590.  
  591.       SDEF (boolean, _bfd_slurp_armap, (bfd *));
  592.       SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *));
  593.       SDEF (void,   _bfd_truncate_arname, (bfd *, CONST char *, char *));
  594.       SDEF (boolean, write_armap, (bfd *arch, 
  595.                                    unsigned int elength,
  596.                                    struct orl *map,
  597.                                    int orl_count, 
  598.                                    int stridx));
  599.  
  600.    Standard stuff.
  601.  
  602.        SDEF (boolean, _close_and_cleanup, (bfd *));
  603.        SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR,
  604.                                                  file_ptr, bfd_size_type));
  605.        SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR, 
  606.                                                  file_ptr, bfd_size_type));
  607.        SDEF (boolean, _new_section_hook, (bfd *, sec_ptr));
  608.  
  609.    Symbols and reloctions
  610.  
  611.       SDEF (unsigned int, _get_symtab_upper_bound, (bfd *));
  612.        SDEF (unsigned int, _bfd_canonicalize_symtab,
  613.                 (bfd *, struct symbol_cache_entry **));
  614.        SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr));
  615.        SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **,
  616.                                                     struct symbol_cache_entry**));
  617.        SDEF (struct symbol_cache_entry  *, _bfd_make_empty_symbol, (bfd *));
  618.        SDEF (void,     _bfd_print_symbol, (bfd *, PTR, struct symbol_cache_entry  *,
  619.                                            bfd_print_symbol_enum_type));
  620.      #define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
  621.        SDEF (alent *,   _get_lineno, (bfd *, struct symbol_cache_entry  *));
  622.      
  623.        SDEF (boolean,   _bfd_set_arch_mach, (bfd *, enum bfd_architecture,
  624.                                             unsigned long));
  625.      
  626.        SDEF (bfd *,  openr_next_archived_file, (bfd *arch, bfd *prev));
  627.        SDEF (boolean, _bfd_find_nearest_line,
  628.              (bfd *abfd, struct sec  *section,
  629.               struct symbol_cache_entry  **symbols,bfd_vma offset,
  630.              CONST char **file, CONST char **func, unsigned int *line));
  631.        SDEF (int,    _bfd_stat_arch_elt, (bfd *, struct stat *));
  632.      
  633.        SDEF (int,    _bfd_sizeof_headers, (bfd *, boolean));
  634.      
  635.        SDEF (void, _bfd_debug_info_start, (bfd *));
  636.        SDEF (void, _bfd_debug_info_end, (bfd *));
  637.        SDEF (void, _bfd_debug_info_accumulate, (bfd *, struct sec  *));
  638.  
  639.    Special entry points for gdb to swap in coff symbol table parts
  640.  
  641.        SDEF(void, _bfd_coff_swap_aux_in,(
  642.             bfd            *abfd ,
  643.             PTR             ext,
  644.             int             type,
  645.             int             class ,
  646.             PTR             in));
  647.      
  648.        SDEF(void, _bfd_coff_swap_sym_in,(
  649.             bfd            *abfd ,
  650.             PTR             ext,
  651.             PTR             in));
  652.      
  653.        SDEF(void, _bfd_coff_swap_lineno_in,  (
  654.             bfd            *abfd,
  655.             PTR            ext,
  656.             PTR             in));
  657.      
  658.      } bfd_target;
  659.  
  660. `bfd_find_target'
  661. .................
  662.  
  663.    Returns a pointer to the transfer vector for the object target
  664. named target_name.  If target_name is NULL, chooses the one in the
  665. environment variable GNUTARGET; if that is null or not defined then
  666. the first entry in the target list is chosen.  Passing in the string
  667. "default" or setting the environment variable to "default" will cause
  668. the first entry in the target list to be returned, and
  669. "target_defaulted" will be set in the BFD.  This causes
  670. `bfd_check_format' to loop over all the targets to find the one that
  671. matches the file being read.
  672.  
  673.      bfd_target * bfd_find_target(CONST char *, bfd *);
  674.  
  675. `bfd_target_list'
  676. .................
  677.  
  678.    This function returns a freshly malloced NULL-terminated vector of
  679. the names of all the valid BFD targets. Do not modify the names
  680.  
  681.      CONST char ** bfd_target_list();
  682.  
  683.  
  684. 
  685. File: bfd.info,  Node: Architectures,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  686.  
  687. Architectures
  688. =============
  689.  
  690.    BFD's idea of an architecture is implimented in `archures.c'. BFD
  691. keeps two atoms in a BFD describing the architecture of the data
  692. attached to the BFD, the `enum bfd_architecture arch' field and the
  693. `unsigned long machine' field.
  694.  
  695. `bfd_architecture'
  696. ..................
  697.  
  698.    This enum gives the object file's CPU architecture, in a global
  699. sense.  E.g. what processor family does it belong to   There is
  700. another field, which indicates what processor within the family is in
  701. use.  The machine gives a number which distingushes different
  702. versions of the architecture, containing for example 2 and 3 for
  703. Intel i960 KA and i960 KB, and 68020 and 68030 for Motorola 68020 and
  704. 68030.
  705.  
  706.      enum bfd_architecture 
  707.      {
  708.        bfd_arch_unknown,   /* File arch not known */
  709.        bfd_arch_obscure,   /* Arch known, not one of these */
  710.        bfd_arch_m68k,      /* Motorola 68xxx */
  711.        bfd_arch_vax,       /* DEC Vax */   
  712.        bfd_arch_i960,      /* Intel 960 */
  713.          /* The order of the following is important.
  714.             lower number indicates a machine type that 
  715.             only accepts a subset of the instructions
  716.             available to machines with higher numbers.
  717.             The exception is the "ca", which is
  718.             incompatible with all other machines except 
  719.             "core". */
  720.      
  721.      #define bfd_mach_i960_core      1
  722.      #define bfd_mach_i960_ka_sa     2
  723.      #define bfd_mach_i960_kb_sb     3
  724.      #define bfd_mach_i960_mc        4
  725.      #define bfd_mach_i960_xa        5
  726.      #define bfd_mach_i960_ca        6
  727.      
  728.        bfd_arch_a29k,      /* AMD 29000 */
  729.        bfd_arch_sparc,     /* SPARC */
  730.        bfd_arch_mips,      /* MIPS Rxxxx */
  731.        bfd_arch_i386,      /* Intel 386 */
  732.        bfd_arch_ns32k,     /* National Semiconductor 32xxx */
  733.        bfd_arch_tahoe,     /* CCI/Harris Tahoe */
  734.        bfd_arch_i860,      /* Intel 860 */
  735.        bfd_arch_romp,      /* IBM ROMP RS/6000 */
  736.        bfd_arch_alliant,   /* Alliant */
  737.        bfd_arch_convex,    /* Convex */
  738.        bfd_arch_m88k,      /* Motorola 88xxx */
  739.        bfd_arch_pyramid,   /* Pyramid Technology */
  740.        bfd_arch_h8_300,    /* Hitachi H8/300 */
  741.        bfd_arch_last
  742.        };
  743.  
  744.    stuff
  745.  
  746. `bfd_prinable_arch_mach'
  747. ........................
  748.  
  749.    Return a printable string representing the architecture and
  750. machine type. The result is only good until the next call to
  751. `bfd_printable_arch_mach'.
  752.  
  753.      CONST char * bfd_printable_arch_mach(enum bfd_architecture arch, unsigned long machine);
  754.  
  755. `bfd_scan_arch_mach'
  756. ....................
  757.  
  758.    Scan a string and attempt to turn it into an archive and machine
  759. type combination.
  760.  
  761.      boolean bfd_scan_arch_mach(CONST char *, enum bfd_architecture *, unsigned long *);
  762.  
  763. `bfd_arch_compatible'
  764. .....................
  765.  
  766.    This routine is used to determine whether two BFDs' architectures
  767. and machine types are compatible.  It calculates the lowest common
  768. denominator between the two architectures and machine types implied
  769. by the BFDs and sets the objects pointed at by ARCHP and MACHINE if
  770. non NULL.
  771.  
  772.    This routine returns `true' if the BFDs are of compatible type,
  773. otherwise `false'.
  774.  
  775.      boolean bfd_arch_compatible(bfd *abfd,
  776.           bfd *bbfd,
  777.           enum bfd_architecture *archp,
  778.           unsigned long *machinep);
  779.  
  780. `bfd_set_arch_mach'
  781. ...................
  782.  
  783.    Set atch mach
  784.  
  785.      #define bfd_set_arch_mach(abfd, arch, mach) \
  786.           BFD_SEND (abfd, _bfd_set_arch_mach,\
  787.                          (abfd, arch, mach))
  788.  
  789.  
  790. 
  791. File: bfd.info,  Node: Opening and Closing,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  792.  
  793. Opening and Closing BFDs
  794. ========================
  795.  
  796. `bfd_openr'
  797. ...........
  798.  
  799.    Opens the file supplied (using `fopen') with the target supplied,
  800. it returns a pointer to the created BFD.
  801.  
  802.    If NULL is returned then an error has occured.  Possible errors
  803. are no_memory, invalid_target or system_call error.
  804.  
  805.      bfd* bfd_openr(CONST char *filename,CONST char*target);
  806.  
  807. `bfd_fdopenr'
  808. .............
  809.  
  810.    bfd_fdopenr is to bfd_fopenr much like  fdopen is to fopen. It
  811. opens a BFD on a file already described by the FD supplied.
  812.  
  813.    Possible errors are no_memory, invalid_target and system_call error.
  814.  
  815.      bfd * bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
  816.  
  817. `bfd_openw'
  818. ...........
  819.  
  820.    Creates a BFD, associated with file FILENAME, using the file
  821. format TARGET, and returns a pointer to it.
  822.  
  823.    Possible errors are system_call_error, no_memory, invalid_target.
  824.  
  825.      bfd * bfd_openw(CONST char *filename, CONST char *target);
  826.  
  827. `bfd_close'
  828. ...........
  829.  
  830.    This function closes a BFD. If the BFD was open for writing, then
  831. pending operations are completed and the file written out and closed.
  832. If the created file is executable, then `chmod' is called to mark it
  833. as such.
  834.  
  835.    All memory attached to the BFD's obstacks is released.
  836.  
  837.    `true' is returned if all is ok, otherwise `false'.
  838.  
  839.      boolean bfd_close(bfd *);
  840.  
  841. `bfd_create'
  842. ............
  843.  
  844.    This routine creates a new BFD in the manner of `bfd_openw', but
  845. without opening a file. The new BFD takes the target from the target
  846. used by TEMPLATE. The format is always set to `bfd_object'.
  847.  
  848.      bfd * bfd_create(CONST char *filename, bfd *template);
  849.  
  850. `bfd_alloc_size'
  851. ................
  852.  
  853.    Return the number of bytes in the obstacks connected to the
  854. supplied BFD.
  855.  
  856.      bfd_size_type bfd_alloc_size(bfd *abfd);
  857.  
  858.  
  859. 
  860. File: bfd.info,  Node: Internal,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  861.  
  862. `bfd_put_size'
  863. ..............
  864.  
  865. `bfd_get_size'
  866. ..............
  867.  
  868.    These macros as used for reading and writing raw data in sections;
  869. each access (except for bytes) is vectored through the target format
  870. of the BFD and mangled accordingly. The mangling performs any
  871. necessary endian translations and removes alignment restrictions.
  872.  
  873.      #define bfd_put_8(abfd, val, ptr) \
  874.                      (*((char *)ptr) = (char)val)
  875.      #define bfd_get_8(abfd, ptr) \
  876.                      (*((char *)ptr))
  877.      #define bfd_put_16(abfd, val, ptr) \
  878.                      BFD_SEND(abfd, bfd_putx16, (val,ptr))
  879.      #define bfd_get_16(abfd, ptr) \
  880.                      BFD_SEND(abfd, bfd_getx16, (ptr))
  881.      #define bfd_put_32(abfd, val, ptr) \
  882.                      BFD_SEND(abfd, bfd_putx32, (val,ptr))
  883.      #define bfd_get_32(abfd, ptr) \
  884.                      BFD_SEND(abfd, bfd_getx32, (ptr))
  885.      #define bfd_put_64(abfd, val, ptr) \
  886.                      BFD_SEND(abfd, bfd_putx64, (val, ptr))
  887.      #define bfd_get_64(abfd, ptr) \
  888.                      BFD_SEND(abfd, bfd_getx64, (ptr))
  889.  
  890.    *-*/
  891.  
  892. `bfd_h_put_size'
  893. ................
  894.  
  895. `bfd_h_get_size'
  896. ................
  897.  
  898.    These macros have the same function as their `bfd_get_x'
  899. bretherin, except that they are used for removing information for the
  900. header records of object files. Believe it or not, some object files
  901. keep their header records in big endian order, and their data in
  902. little endan order.
  903.  
  904.      #define bfd_h_put_8(abfd, val, ptr) \
  905.                      (*((char *)ptr) = (char)val)
  906.      #define bfd_h_get_8(abfd, ptr) \
  907.                      (*((char *)ptr))
  908.      #define bfd_h_put_16(abfd, val, ptr) \
  909.                      BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
  910.      #define bfd_h_get_16(abfd, ptr) \
  911.                      BFD_SEND(abfd, bfd_h_getx16,(ptr))
  912.      #define bfd_h_put_32(abfd, val, ptr) \
  913.                      BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
  914.      #define bfd_h_get_32(abfd, ptr) \
  915.                      BFD_SEND(abfd, bfd_h_getx32,(ptr))
  916.      #define bfd_h_put_64(abfd, val, ptr) \
  917.                      BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
  918.      #define bfd_h_get_64(abfd, ptr) \
  919.                      BFD_SEND(abfd, bfd_h_getx64,(ptr))
  920.  
  921.    *-*/
  922.  
  923. `bfd_log2'
  924. ..........
  925.  
  926.    Return the log base 2 of the value supplied, rounded up. eg an arg
  927. of 1025 would return 11.
  928.  
  929.      bfd_vma bfd_log2(bfd_vma x);
  930.  
  931.  
  932. 
  933. File: bfd.info,  Node: File Caching,  Next: BFD back end,  Prev: BFD front end,  Up: Top
  934.  
  935. File Caching
  936. ============
  937.  
  938.    The file caching mechanism is embedded within BFD and allows the
  939. application to open as many BFDs as it wants without regard to the
  940. underlying operating system's file descriptor limit (often as low as
  941. 20 open files).
  942.  
  943.    The module in `cache.c' maintains a least recently used list of
  944. `BFD_CACHE_MAX_OPEN' files, and exports the name `bfd_cache_lookup'
  945. which runs around and makes sure that the required BFD is open. If
  946. not, then it chooses a file to close, closes it and opens the one
  947. wanted, returning its file handle.
  948.  
  949. `BFD_CACHE_MAX_OPEN'
  950. ....................
  951.  
  952.    The maxiumum number of files which the cache will keep open at one
  953. time.
  954.  
  955.      #define BFD_CACHE_MAX_OPEN 10
  956.  
  957. `bfd_last_cache'
  958. ................
  959.  
  960.    Zero, or a pointer to the topmost BFD on the chain.  This is used
  961. by the `bfd_cache_lookup' macro in `libbfd.h' to determine when it
  962. can avoid a function call.
  963.  
  964.      extern bfd *bfd_last_cache;
  965.  
  966. `bfd_cache_lookup'
  967. ..................
  968.  
  969.    Checks to see if the required BFD is the same as the last one
  970. looked up. If so then it can use the iostream in the BFD with
  971. impunity, since it can't have changed since the last lookup,
  972. otherwise it has to perform the complicated lookup function
  973.  
  974.      #define bfd_cache_lookup(x) \
  975.           ((x)==bfd_last_cache
  976.       \
  977.              (FILE*)(bfd_last_cache->iostream): \
  978.               bfd_cache_lookup_worker(x))
  979.  
  980. `bfd_cache_init'
  981. ................
  982.  
  983.    Initialize a BFD by putting it on the cache LRU.
  984.  
  985.      void bfd_cache_init(bfd *);
  986.  
  987. `bfd_cache_close'
  988. .................
  989.  
  990.    Remove the BFD from the cache. If the attached file is open, then
  991. close it too.
  992.  
  993.      void bfd_cache_close(bfd *);
  994.  
  995. `bfd_open_file'
  996. ...............
  997.  
  998.    Call the OS to open a file for this BFD.  Returns the FILE *
  999. (possibly null) that results from this operation.  Sets up the BFD so
  1000. that future accesses know the file is open. If the FILE * returned is
  1001. null, then there is won't have been put in the cache, so it won't
  1002. have to be removed from it.
  1003.  
  1004.      FILE * bfd_open_file(bfd *);
  1005.  
  1006. `bfd_cache_lookup_worker'
  1007. .........................
  1008.  
  1009.    Called when the macro `bfd_cache_lookup' fails to find a quick
  1010. answer. Finds a file descriptor for this BFD.  If necessary, it open
  1011. it.  If there are already more than BFD_CACHE_MAX_OPEN files open, it
  1012. trys to close one first, to avoid running out of file descriptors.
  1013.  
  1014.      FILE * bfd_cache_lookup_worker(bfd *);
  1015.  
  1016.  
  1017. 
  1018. File: bfd.info,  Node: BFD back end,  Next: Index,  Prev: BFD front end,  Up: Top
  1019.  
  1020. BFD back end
  1021. ************
  1022.  
  1023. * Menu:
  1024.  
  1025. * What to put where::
  1026. * aout ::    a.out backends
  1027. * coff ::    coff backends
  1028.  
  1029.  
  1030. 
  1031. File: bfd.info,  Node: What to Put Where,  Next: Index,  Prev: BFD back end,  Up: Top
  1032.  
  1033.    All of BFD lives in one directory.
  1034.  
  1035.  
  1036. 
  1037. File: bfd.info,  Node: aout,  Next: Index,  Prev: BFD back end,  Up: Top
  1038.  
  1039. a.out backends
  1040. ==============
  1041.  
  1042.    BFD supports a number of different flavours of a.out format,
  1043. though the major differences are only the sizes of the structures on
  1044. disk, and the shape of the relocation information.
  1045.  
  1046.    The support is split into a basic support file `aoutx.h' and other
  1047. files which derive functions from the base. One derivation file is
  1048. `aoutf1.h' (for a.out flavour 1), and adds to the basic a.out
  1049. functions support for sun3, sun4, 386 and 29k a.out files, to create
  1050. a target jump vector for a specific target.
  1051.  
  1052.    This information is further split out into more specific files for
  1053. each machine, including `sunos.c' - for sun3 and sun4 and `demo64'
  1054. for a demonstration of a 64 bit a.out format.
  1055.  
  1056.    The base file `aoutx.h' defines general mechanisms for reading and
  1057. writing records to and from disk, and various other methods which BFD
  1058. requires. It is included by `aout32.c' and `aout64.c' to form the
  1059. names aout_32_swap_exec_header_in, aout_64_swap_exec_header_in, etc.
  1060.  
  1061.    As an example, this is what goes on to make the back end for a
  1062. sun4, from aout32.c
  1063.  
  1064.         #define ARCH_SIZE 32
  1065.         #include "aoutx.h"
  1066.  
  1067.    Which exports names:
  1068.  
  1069.          ...
  1070.         aout_32_canonicalize_reloc
  1071.         aout_32_find_nearest_line
  1072.         aout_32_get_lineno
  1073.         aout_32_get_reloc_upper_bound
  1074.           ...
  1075.  
  1076.     from sunos.c
  1077.  
  1078.          #define ARCH 32
  1079.          #define TARGET_NAME "a.out-sunos-big"
  1080.          #define VECNAME    sunos_big_vec
  1081.          #include "aoutf1.h"
  1082.  
  1083.    requires all the names from aout32.c, and produces the jump vector
  1084.  
  1085.          sunos_big_vec
  1086.  
  1087.    The file host-aout.c is a special case.  It is for a large set of
  1088. hosts that use "more or less standard" a.out files, and for which
  1089. cross-debugging is not interesting.  It uses the standard 32-bit
  1090. a.out support routines, but determines the file offsets and addresses
  1091. of the text, data, and BSS sections, the machine architecture and
  1092. machine type, and the entry point address, in a host-dependent
  1093. manner.  Once these values have been determined, generic code is used
  1094. to handle the  object file.
  1095.  
  1096.    When porting it to run on a new system, you must supply:
  1097.  
  1098.    HOST_PAGE_SIZE         HOST_SEGMENT_SIZE         HOST_MACHINE_ARCH
  1099.      (optional)         HOST_MACHINE_MACHINE    (optional)        
  1100. HOST_TEXT_START_ADDR         HOST_STACK_END_ADDR
  1101.  
  1102.    in the file ../include/sys/h-XXX.h (for your host).  These values,
  1103. plus the structures and macros defined in <a.out.h> on your host
  1104. system, will produce a BFD target that will access ordinary a.out
  1105. files on your host.
  1106.  
  1107.    To configure a new machine to use host-aout.c, specify:
  1108.  
  1109.    TDEFINES = -DDEFAULT_VECTOR=host_aout_big_vec TDEPFILES=
  1110. host-aout.o trad-core.o
  1111.  
  1112.    in the config/tmake-XXX file, and modify configure.in to use the
  1113. tmake-XXX file (by setting "bfd_target=XXX") when your configuration
  1114. is selected.
  1115.  
  1116. relocations
  1117. -----------
  1118.  
  1119.    The file `aoutx.h' caters for both the *standard* and *extended*
  1120. forms of a.out relocation records.
  1121.  
  1122.    The standard records are characterised by containing only an
  1123. address, a symbol index and a type field. The extended records (used
  1124. on 29ks and sparcs) also have a full integer for an addend.
  1125.  
  1126. Internal Entry Points
  1127. ---------------------
  1128.  
  1129.    `aoutx.h' exports several routines for accessing the contents of
  1130. an a.out file, which are gathered and exported in turn by various
  1131. format specific files (eg sunos.c).
  1132.  
  1133. `aout_<size>_swap_exec_header_in'
  1134. .................................
  1135.  
  1136.    Swaps the information in an executable header taken from a raw
  1137. byte stream memory image, into the internal exec_header structure.
  1138.  
  1139.      void aout_<size>_swap_exec_header_in(bfd *abfd,
  1140.            struct external_exec *raw_bytes,
  1141.            struct internal_exec *execp);
  1142.  
  1143. `aout_<size>_swap_exec_header_out'
  1144. ..................................
  1145.  
  1146.    Swaps the information in an internal exec header structure into
  1147. the supplied buffer ready for writing to disk.
  1148.  
  1149.      void aout_<size>_swap_exec_header_out(bfd *abfd,
  1150.             struct internal_exec *execp,
  1151.             struct external_exec *raw_bytes);
  1152.  
  1153. `aout_<size>_some_aout_object_p'
  1154. ................................
  1155.  
  1156.     Some A.OUT variant thinks that the file whose format we're
  1157. checking is an a.out file.  Do some more checking, and set up for
  1158. access if it really is.  Call back to the calling environments
  1159. "finish up" function just before returning, to handle any last-minute
  1160. setup.
  1161.  
  1162.      bfd_target * aout_<size>_some_aout_object_p(bfd *abfd,
  1163.            bfd_target *(*callback_to_real_object_p)());
  1164.  
  1165. `aout_<size>_mkobject'
  1166. ......................
  1167.  
  1168.     This routine initializes a BFD for use with a.out files.
  1169.  
  1170.      boolean aout_<size>_mkobject(bfd *);
  1171.  
  1172. `aout_<size>_machine_type'
  1173. ..........................
  1174.  
  1175.     Keep track of machine architecture and machine type for a.out's. 
  1176. Return the machine_type for a particular arch&machine, or M_UNKNOWN
  1177. if that exact arch&machine can't be represented in a.out format.
  1178.  
  1179.    If the architecture is understood, machine type 0 (default) should
  1180. always be understood.
  1181.  
  1182.      enum machine_type aout_<size>_machine_type(enum bfd_architecture arch,
  1183.            unsigned long machine);
  1184.  
  1185. `aout_<size>_set_arch_mach'
  1186. ...........................
  1187.  
  1188.     Sets the architecture and the machine of the BFD to those values
  1189. supplied. Verifies that the format can support the architecture
  1190. required.
  1191.  
  1192.      boolean aout_<size>_set_arch_mach(bfd *,
  1193.            enum bfd_architecture,
  1194.            unsigned long machine);
  1195.  
  1196. `aout_<size>new_section_hook'
  1197. .............................
  1198.  
  1199.     Called by the BFD in response to a `bfd_make_section' request.
  1200.  
  1201.      boolean aout_<size>_new_section_hook(bfd *abfd,
  1202.            asection *newsect);
  1203.  
  1204.  
  1205.